package main

import (
	"Ljohn/structtest/alignment"
	"bytes"
	"fmt"
	"reflect"
	"strconv"
	"unsafe"
)

func main() {
	//compareTest()
	t1()
	//t12()
}

type Name struct {
	S string
}

func t12() {
	t := &Name{}
	innerT1(t)
	fmt.Println("-------")
	innerT1(t)
	fmt.Println("-------")
	innerT1(t)
}

var count = 0

func innerT1(t *Name) *Name {
	count++
	t.S = t.S + strconv.Itoa(count)
	fmt.Println(t.S)
	return t
}

func compareTest() {
	baseCompare()
	type T struct {
		A string
		B int
		C []int
	}
	ai := []int{1, 2}
	bi := []int{1, 2, 3}
	a := T{"a", 0, ai}
	b := T{"a", 1, ai}
	c := b
	c.C = bi
	fmt.Println(reflect.DeepEqual(a, b))
	fmt.Println(reflect.DeepEqual(b, c))
}

func baseCompare() {
	type T struct {
		A string
		B int
	}
	a := T{A: "a", B: 0}
	b := T{A: "a", B: 1}
	fmt.Println(a == b)
}

func t1() {
	/*	structFuncTest()
		//............
		t := &test{}
		t.Hi()*/
	//alignment.OutLine()
	alignment.OutLine1()

	/*	inherit.Exec()
		baseTypeTest.Open()*/
	//nilStructTest()

	s := T{}
	fmt.Printf("%p\n", &s)
	s.Test1()
	fmt.Printf("%p\n", &s)
	a := T{}
	fmt.Printf("%p\n", &a)
	a.Test2()
	fmt.Printf("%p\n", &a)
	b := &T{}
	fmt.Printf("%p\n", &b)
	b.Test3()
	fmt.Printf("%p\n", b)
	c := new(T)
	fmt.Printf("%p\n", &c)
	fmt.Printf("%p\n", c)
}

type T struct {
}

func (m *T) Test1() {
	fmt.Println("...")
}

func (m *T) Test2() {
	fmt.Println("!!")
}

func (m *T) Test3() {
	fmt.Println("@@")
}

type name struct {
}

type testI struct {
	sss
	s string
}

type sss int

func (_ *sss) Sai() {

}

func runGo() {
	s := &testI{}
	s.s = "22"
	s.Sai()
}

type Q1 struct {
	testT int
	S     []int
	Q2
}

type Q2 uint8

func (q Q2) test() {
	q = 1
	fmt.Println("I'm Q2 Function")
}
func (q *Q2) test1() {
	*q = 2
	fmt.Println("I'm *Q2 Function")
}

func structFuncTest() {

	t := &Q1{testT: 10, Q2: Q2(4)}
	t.S = append(t.S, 1, 2)

	fmt.Println(t.S[2])
	return

	t.test()
	fmt.Println(t)
	t.test1()
	fmt.Println(t)
}

type test struct {
	Age  int
	Name string
	bytes.Buffer
	t2
}

type t2 int

func (t *t2) Hi() {
	fmt.Println("....")
}

type Nil1 struct {
}

type Nil2 struct {
}
type Nil3 struct {
	Id1 int
	Id2 int
}

func nilStructTest() {
	var t11 = Nil1{}
	var t12 = new(Nil1)
	var t13 = &Nil1{}
	var t21 = Nil2{}
	var t22 = new(Nil2)
	var t23 = &Nil2{}
	var t24 = new(Nil2)
	var t31 = Nil3{}
	var t32 = new(Nil3)
	var t33 = &Nil3{}
	var t34 = Nil3{}

	var tt interface{} = nil

	fmt.Printf("%v,%p,%v       ", t11, &t11, unsafe.Sizeof(t11))
	fmt.Printf("%v,%p,%v       ", t12, &t12, unsafe.Sizeof(t12))
	fmt.Printf("%v,%p,%v        \n", t13, &t13, unsafe.Sizeof(t13))

	fmt.Printf("%v,%p,%v       ", t21, &t21, unsafe.Sizeof(t21))
	fmt.Printf("%v,%p,%v       ", t22, &t22, unsafe.Sizeof(t22))
	fmt.Printf("%v,%p,%v       ", t24, &t24, unsafe.Sizeof(t24))
	fmt.Printf("%v,%p,%v        \n", t23, &t23, unsafe.Sizeof(t23))

	fmt.Printf("%v,%p,%v       ", t31, &t31, unsafe.Sizeof(t31))
	fmt.Printf("%v,%p,%v       ", t32, &t32, unsafe.Sizeof(t32))
	fmt.Printf("%v,%p,%v        ", t33, &t33, unsafe.Sizeof(t33))
	fmt.Printf("%v,%p,%v        \n", t34, &t34, unsafe.Sizeof(t34))

	fmt.Printf("%v,%p,%v        \n", tt, &tt, unsafe.Sizeof(tt))

}
